Skip to content

fix(abstractions): improve parameter collection sanitization and ISO duration validation - #883

Merged
Vincent Biret (baywet) merged 6 commits into
microsoft:mainfrom
hardikkaurani:fix/parameter-collection-sanitization-and-duration-validation
Nov 9, 2026
Merged

Vincent Biret (baywet) merged 6 commits into
microsoft:mainfrom
hardikkaurani:fix/parameter-collection-sanitization-and-duration-validation

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Overview

As requested in #867 (comment), this pull request extracts the parameter collection sanitization and ISO duration component validation changes from PR #867 into a dedicated PR:

  1. Parameter Collection Sanitization and Null Filtering (request_information.py):

    • In RequestInformation._get_sanitized_value(), collections containing None elements (e.g. [None, 'active'] or all-None lists [None, None]) previously passed None elements directly to StdUriTemplate.expand(), triggering ValueError: Illegal class passed as substitution: None.
    • Furthermore, enum collection normalization previously used all(isinstance(x, Enum) for x in value). When an enum list contained a leading None (e.g. [None, Status.Active]), the check evaluated to False and bypassed comma-joining, producing an unnormalized list of scalar strings rather than a comma-joined enum string.
    • Updated _get_sanitized_value() to filter None elements and inspect surviving non-null elements, ensuring order-independent enum normalization regardless of leading/trailing/interleaved None entries, and returning an empty collection when all elements are None.
  2. Component Validation in ISO 8601 Duration Parser (date_utils.py):

    • parse_timedelta_from_iso_format() previously evaluated date/time group values (years or months or days and hours or minutes or seconds) numerically rather than checking presence of match groups. As a result, duration strings without components (such as "P" or "PT") and weeks combined with zero-valued time designators (such as "P1WT0S") were incorrectly parsed as timedelta(0) or allowed without error.
    • Updated duration component presence checks using bool(m.group(...)) and ensured durations lacking any date, time, or week components raise a ValueError.

Changes

  • packages/abstractions/kiota_abstractions/date_utils.py:
    • Validate that at least one date, time, or week component is matched; raise ValueError on empty strings like "P" or "PT".
  • packages/abstractions/kiota_abstractions/request_information.py:
    • Filter None elements in collection sanitization to prevent substitution errors in StdUriTemplate.
    • Normalize enum collections by inspecting surviving non-null elements.
  • packages/abstractions/tests/test_date_utils.py:
    • Add regression tests for "P", "PT", "P1WT0S", and zero-duration ISO strings.
  • packages/abstractions/tests/test_request_information.py:
    • Add tests for collections with leading/trailing/all None elements and enum collections with None entries in query/path parameters.

Verification

  • pytest: 226 passed.
  • mypy kiota_abstractions: clean (no issues in 48 source files).

…duration parser

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…equirements

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…ization

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…ements in query parameters

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…l entries in parameters

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner November 9, 2026 20:14
Copilot AI balanced review requested due to automatic review settings November 9, 2026 20:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@sonarqubecloud

sonarqubecloud Bot commented Nov 9, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the parameter sanitization and duration validation changes.

No open issues 🎉

Review effort: Balanced

@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Nov 9, 2026
@baywet
Vincent Biret (baywet) added this pull request to the merge queue Nov 9, 2026
Merged via the queue into microsoft:main with commit 80718a1 Nov 9, 2026
69 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

3 participants